package com.wonders.hisdoctor.station.project.allergy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wonders.his.framework.utils.oracle.IdUtils;
import com.wonders.hisdoctor.station.constant.ServiceConstant;
import com.wonders.hisdoctor.station.enums.OracleSequenceEnum;
import com.wonders.hisdoctor.station.project.allergy.service.IAllergyService;
import com.wonders.hisdoctor.station.project.base.domain.PatAllergy;
import com.wonders.hisdoctor.station.project.base.mapper.PatAllergyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author zhaogongming
 * @date 2021-03-22
 **/
@Service
public class AllergyServiceImpl implements IAllergyService {

    @Autowired
    private PatAllergyMapper patAllergyMapper;

    @Autowired
    private IdUtils idUtils;

    @Override
    public Integer save(PatAllergy entity) {
        String patAllergyId = idUtils.getNextVal(OracleSequenceEnum.SEQ_PAT_ALLERGY.getCode()).toString();
        entity.setPatAllergyId(new Long(patAllergyId));
        entity.setStatus(ServiceConstant.ONE_STRING);
        entity.setRegisterTime(new Date());
        return patAllergyMapper.insert(entity);
    }

    @Override
    public Integer delete(PatAllergy entity) {
        entity.setStatus(ServiceConstant.ZERO_STRING);
        entity.setCancelTime(new Date());
        return patAllergyMapper.updateById(entity);
    }

    @Override
    public List<PatAllergy> selectHistory(String patientId) {
        QueryWrapper<PatAllergy> wrapper = new QueryWrapper<>();
        wrapper.eq("PATIENT_ID", patientId);
        wrapper.orderByDesc("REGISTER_TIME");
        return patAllergyMapper.selectList(wrapper);
    }
}
